#!/usr/bin python
# -*- coding:utf-8 -*-                             #中文编码
import sys

reload(sys)  # 不加这部分处理中文还是会出问题
sys.setdefaultencoding('utf-8')
import requests
import json
from collections import defaultdict

def tree():
    return defaultdict(tree)

url = "http://openapi.tuling123.com/openapi/api/v2"
secretcode = "517dabbc2dde2466086ab2bf97cb5d07"
param = defaultdict(tree)
param['reqType'] = 0
param['userInfo']['apiKey'] = secretcode
param['userInfo']['userId'] = 98645788
param['perception']['inputText']['text'] = "你好"
headers = {'Content-Type': 'application/json'}
response = requests.post(url=url, headers=headers, data = json.dumps(param))
print json.loads(response.text) if response.status_code == 200 else ""
resultList = json.loads(response.text)['results']
str1=''
for i,val in enumerate(resultList):
    str1 =  str1 + str(resultList[i]['values']['text'])
print str1
